define(function (require) {
    var _common = require('common/main');
    var _config = require('common/config');
    var _send = _common.sendRequest;
    function init() {
    	$('#mod_food_special_confirm').click(_update_food_special);
    	var _param = {};
    	_send("listFood.ajax",_param,_list_food_render);
    	
    }
    
    function _list_food_render(data)
    {
    	var _html = '';
    	var _len = data.length;
    	var foodid = $('#hiddenfoodid').val();
    	for (var i = 0; i < _len; i++) 
    	{
			var _item = data[i];
			_html += '<option value="';
			_html += _item.id;
			_html += '"';
			if(_item.id==foodid)
				_html += ' selected>';
			else
				_html += '>';
			_html += _item.name;
			_html += '</option>';
    	}
    	$('#food_special_list').html(_html);
    }
    
    function _update_food_special()
    {
    	//get from session or cookie
    	var _userid = 0;
    	var _fooddate = $('#food_special_date').val();
    	var _foodid = $('#food_special_list option:selected').attr("value");
    	var _singlemargin = $('#food_single_margin').val();
    	var _combomargin = $('#food_combo_margin').val();
    	var _id = $('#hiddenid').val();
    	var _param = _common.stringify({
			userid : _userid,
			id : _id,
			fooddate : _fooddate,
			foodid : _foodid,
			singlemargin : _singlemargin,
			combomargin : _combomargin
		});
    	_send("updateSpecial.ajax",_param,_save_render);
    }
    
    function _save_render(data)
    {
    	if(data)
		{
    		alert("修改成功");
    		window.close();
		}
    	else
		{
    		alert("修改失败，请修改后重新提交");
		}
    }
    
    
    return { init: init };
});